﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;

namespace DotNet.Helper
{
    /// <summary>
    /// tcp客户端帮助类
    /// </summary>
    public class TcpClientHelper
    {
        private TcpClient _client;

        #region 属性
        /// <summary>
        /// 主机地址
        /// </summary>
        public string Host { get; set; }
        /// <summary>
        /// 端口
        /// </summary>
        public int Port { get; set; }
        #endregion

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="host">主机地址</param>
        /// <param name="port">端口</param>
        public TcpClientHelper(string host,int port)
        {
            this.Host = host;
            this.Port = port;
        }

        /// <summary>
        /// 连接服务
        /// </summary>
        /// <returns></returns>
        public bool Connect()
        {
            bool result = true;

            try
            {
                _client = new TcpClient();
                _client.Connect(this.Host, this.Port);
            }
            catch (Exception)
            {

                throw;
            }

            return result;
        }

    }
}
